/****************************************************************************
**
** Copyright (C) 2011 Kimitake
** Contact: Kimitake (kimitake@gmail.com)
**
** This file is part of CuteUp application.
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General
** Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** This file is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without evene the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this file. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/

import QtQuick 1.0
import "../res/meetup_ui" 1.0 as UI
import "qml" 1.0 as W

Item {
    id: screen

    property int screenWidth: 480
    property int screenHeight: 640

    //property variant currentUI: startPage
    property variant currentUI: mainWindow
    property variant nextUI: null
    property variant prevUI: null

    property variant pages: [
        startPage, page0020, page0030, page0040, page0050, page0060,
        page0070, mainWindow, page0800, page0900, null
    ]
    property int pageIndex: 0

    width: screenWidth
    height: screenHeight

    //state: "startPage"
    state: "mainWindow"

    function funcPrevPage() {
        console.log("prev");

        if (pageIndex==0)
            return;

        prevUI = pages[pageIndex-1];
        nextUI = currentUI
        currentUI = prevUI

        screen.state = ""
        screen.state = "prevPage"

        pageIndex -= 1;
    }

    function funcNextPage() {
        console.log("next");

        nextUI = pages[pageIndex+1];
        if (nextUI == null)
            return;

        prevUI = currentUI;
        currentUI = nextUI;

        screen.state = ""
        screen.state = "nextPage"

        pageIndex += 1;
    }

	function funcAuthorization() {
		screen.state = "authorization";
	}

	function funcEventsList() {
		screen.state = "eventsList";
	}

	function funcMainWindow() {
		screen.state = "currentPage"
	}

    Rectangle {
        id: base
        anchors.fill: parent
        color: "#000000"

        W.Bio {
            id: startPage
        }

        W.AboutCuteUp {
            id: page0020
        }

        W.FeatureLists {
            id: page0030
        }

        UI.MainWindow {
            id: page0040
            x: parent.width * 1.5
        }

        W.WhatIsOAuth {
            id: page0050
        }

        UI.MainWindow {
            id: page0060
            x: parent.width * 1.5
			onShowAuthorization: { funcAuthorization() }
        }

        W.MeetupAPI {
            id: page0070
        }

		// this MainWindow is used for debug,
		// so it is assign mainWindow as id
        UI.MainWindow {
            id: mainWindow
            x: parent.width * 1.5
			onShowAuthorization: { funcAuthorization() }
            onShowEventsList: { funcEventsList() }
        }

        W.MoreFeatures {
            id: page0800
        }

        W.ThankYou {
            id: page0900
        }

        // prev / next button
        W.PrevNextButtons {
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            width: parent.width
            onPrevPage: { funcPrevPage(); }
            onNextPage: { funcNextPage(); }
        }
/*
		UI.EventsList {
			id: eventsListUI
			x: parent.width * 1.5
			onReturnTo: { funcMainWindow() }
		}
*/
		UI.Authorization {
            id: authorizationUI
            x: (parent.width - width)/2
            y: -height * 1.5
			onAuthorized: { funcMainWindow() }
			onCancel: { funcMainWindow() }
		}
    }

	states: [
		State {
			name: "currentPage"
			PropertyChanges {
				target: currentUI
				x: 0
            }
			PropertyChanges {
				target: eventsListUI
				x: parent.width * 1.5
            }
			PropertyChanges {
				target: authorizationUI
				y: -height * 1.5
			}
        },
		State {
			name: "authorization"
			PropertyChanges {
				target: authorizationUI
				y: 10
			}
			PropertyChanges {
                target: currentUI
                x: 0
				opacity: 0.3
			}
		},
        State {
			name: "eventsList"
			PropertyChanges {
				target: currentUI
				x: screen.width * 1.5
			}
			PropertyChanges {
				target: eventsListUI
				x: 0
			}
		},
        State {
            name: "mainWindow"
            PropertyChanges {
                target: mainWindow
                x: 0
            }
        },
        State {
			name: "startPage"
			PropertyChanges {
				target: startPage
				x: 0
			}
		},
		State {
			name: "nextPage"
			PropertyChanges {
				target: prevUI
				x: parent.width * 1.5
			}
			PropertyChanges {
				target: nextUI
				x: 0
			}
		},
		State {
			name: "prevPage"
			PropertyChanges {
				target: nextUI
				x: parent.width * 1.5
			}
			PropertyChanges {
				target: prevUI
				x: 0
			}
		}
	]
	transitions: [
		Transition {
			NumberAnimation {
				properties: "x,y,opacity";
				duration: 200
			}
		}
	]
}
